package com.cxs.xiaomi.dao.impl;

import com.cxs.xiaomi.dao.GoodsTypeDao;
import com.cxs.xiaomi.domain.GoodsType;
import cxs.handler.impl.ResultHandlerAsBeanImpl;
import cxs.handler.impl.ResultHandlerAsListImpl;
import cxs.templete.JdbcTemplete;

import java.util.List;

/*
 * @Author:cxs
 * @Date:2021/9/14  22:01
 * @Version 1.0
 * @Motto:放下杂念,只为迎接明天更好的自己
 * */
public class GoodsTypeDaoImpl implements GoodsTypeDao {
    @Override
    public List<GoodsType> selectAllList() {
        String sql = "select * from tb_goods_type";
        return JdbcTemplete.DQLTemplete(sql,new ResultHandlerAsListImpl<>(GoodsType.class));
    }

    @Override
    public GoodsType selectById(int id) {
        String sql = "select * from tb_goods_type where id = ?";
        return JdbcTemplete.DQLTemplete(sql,new ResultHandlerAsBeanImpl<>(GoodsType.class),id);
    }

    @Override
    public int insert(GoodsType gt) {
        String sql = "insert into tb_goods_type values(null,?,?,?)";
        return JdbcTemplete.DMLTemplete(sql,gt.getName(),gt.getLevel(),gt.getParent());
    }

    @Override
    public int updateById(GoodsType goodsType) {
        String sql = "update tb_goods_type set name = ? where id = ?";
        return JdbcTemplete.DMLTemplete(sql,goodsType.getName(),goodsType.getId());
    }

    @Override
    public int deleteById(int id) {
        String sql = "delete from tb_goods_type where id = ?";
        return JdbcTemplete.DMLTemplete(sql,id);
    }
}
